
package com.foreveross.mofang.serviceconsole.web.controller.interfaces;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.mofang.serviceconsole.application.core.NodeRegisterApplication;
import com.foreveross.mofang.serviceconsole.application.dto.NodeRegisterDTO;
import com.foreveross.mofang.serviceconsole.web.controller.common.BaseController;
import com.foreveross.mofang.serviceconsole.web.controller.common.LogAn;

/**
 * 结点注册对外开放调用入口
 * 
 * @author fb 
 *
 */
@Controller
@RequestMapping("/interface/NodeRegister")
public class NodeRegisterInterface extends BaseController{
		
	@Inject
	private NodeRegisterApplication nodeRegisterApplication;
	
	@LogAn(name = "联机注册",  params = {"nodeRegister.nodeSn"})
	@ResponseBody
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public Map<String, Object> register(@Valid NodeRegisterDTO nodeRegister) {
		Map<String, Object> result = new HashMap<String, Object>();
		nodeRegisterApplication.nodeRegister(nodeRegister);
		result.put("result", "success");
		return result;
	}
	
	@LogAn(name = "心跳连接", params = {"nodeSn"})
	@ResponseBody
	@RequestMapping(value = "/heartbeat/{nodeSn}", method = RequestMethod.GET)
	public Map<String, Object> heartbeat(@PathVariable String nodeSn) {
		Map<String, Object> result = new HashMap<String, Object>();
		nodeRegisterApplication.heartbeat(nodeSn);
		result.put("result", "success");
		
		return result;
	}
}
